home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / probots.arc / MARVIN.PR < prev    next >
Text File  |  1991-04-28  |  5KB  |  155 lines

  1.   PROCEDURE Marvin;
  2.  
  3.     { MARVIN - the not-so-paranoid robot }
  4. { Original C-Robot Created by:
  5.   Andrew Broding c/o the TASK Robot Development Factory }
  6.  
  7.   VAR
  8.     degree         : Integer; { degree for motion }
  9.     course         : Integer; { degree for firing }
  10.     old_dam        : Integer; { last damage check }
  11.     Range          : Integer;         
  12.     res            : Integer;              
  13.     srdegree       : Integer;
  14.  
  15.  
  16.     PROCEDURE hitem; { hit a target }
  17.     VAR fdeg       : Integer; { fire degree }
  18.       frange         : Integer; { firing range }
  19.       index          : Integer;                           
  20.     BEGIN
  21.       fdeg := course-5; { set resolution to +/- 5 }
  22.       index := 2;
  23.       WHILE (index > 0) AND (scan(fdeg, 5) = 0) DO
  24.         BEGIN
  25.           fdeg := fdeg+10;
  26.           index := index-1;
  27.         END; 
  28.       frange := scan(fdeg, 5);
  29.       IF (frange > 0) THEN {didn't lose him }
  30.         BEGIN
  31.           IF (frange > 40) AND (frange < 800) THEN { good shooting range }
  32.             cannon(fdeg, frange);
  33.           fdeg := fdeg-4; { set resolution +/- 3 }
  34.           index := 4;
  35.           WHILE (index > 0) AND (scan(fdeg, 1) = 0) DO
  36.             BEGIN
  37.               fdeg := fdeg+3;
  38.               index := index-1;
  39.             END; 
  40.           frange := scan(fdeg, 5);
  41.           IF (frange > 0) THEN {didn't lose him }
  42.             BEGIN
  43.               IF (frange > 40) AND (frange < 800) THEN { good shooting range }
  44.                 cannon(fdeg, frange);
  45.               fdeg := fdeg-1; { set resolution +/- 0 }
  46.               index := 3;
  47.               WHILE (index > 0) AND (scan(fdeg, 0) = 0) DO
  48.                 BEGIN
  49.                   fdeg := fdeg+1;
  50.                   index := index-1;
  51.                 END; 
  52.               frange := scan(fdeg, 5);
  53.               IF (frange > 0) THEN {didn't lose him }
  54.                 BEGIN
  55.                   IF (frange > 40) AND (frange < 800) THEN { good shooting range }
  56.                     BEGIN 
  57.                       cannon(fdeg, frange);
  58.                       cannon(fdeg, frange);
  59.                     END; 
  60.                   course := fdeg;
  61.                 END;
  62.             END;
  63.         END;
  64.     END; 
  65.  
  66.  
  67.     PROCEDURE chkloc;
  68.       {  redirect robot to new degree if it is nearing a wall }
  69.     BEGIN 
  70.       IF (loc_x < 300) THEN { left side }
  71.         BEGIN 
  72.           IF (loc_y < 300) THEN { bottom left }
  73.             degree := 45
  74.           ELSE
  75.             BEGIN 
  76.               IF (loc_y > 700) THEN { top left }
  77.                 degree := 315
  78.               ELSE
  79.                 degree := 0;
  80.             END;     
  81.         END
  82.  
  83.       ELSE IF (loc_x > 700) THEN { right side }
  84.         BEGIN 
  85.           IF (loc_y < 300) THEN { bottom right }
  86.             degree := 125
  87.           ELSE
  88.             BEGIN 
  89.               IF (loc_y > 700) THEN { top right }
  90.                 degree := 225
  91.               ELSE
  92.                 degree := 180;
  93.             END;     
  94.         END; 
  95.  
  96.       IF (loc_y < 300) THEN { bottom side }
  97.         BEGIN 
  98.           IF (loc_x < 300) THEN
  99.             degree := 45
  100.           ELSE
  101.             BEGIN 
  102.               IF (loc_x > 700) THEN
  103.                 degree := 125
  104.               ELSE
  105.                 degree := 90;
  106.             END;     
  107.         END
  108.  
  109.       ELSE IF (loc_y > 700) THEN {  top side }
  110.         BEGIN 
  111.           IF (loc_x < 300) THEN
  112.             degree := 315
  113.           ELSE
  114.             BEGIN 
  115.               IF (loc_x > 700) THEN
  116.                 degree := 225
  117.               ELSE
  118.                 degree := 270;
  119.             END;     
  120.         END; 
  121.     END; {chkloc}
  122.  
  123.  
  124.   BEGIN {Marvin Main}
  125.     res := 10; { scan resolotion }
  126.     degree := 180; { initialize degree }
  127.     srdegree := degree; { initialize cannon }
  128.     chkloc; { out of bounds ? }
  129.     WHILE True DO {Loop Forever}
  130.       BEGIN 
  131.         old_dam := damage;
  132.         WHILE (old_dam = damage) DO
  133.           BEGIN                
  134.             chkloc; { out of bounds ? }
  135.             drive(degree, 100);
  136.             course := srdegree; { set fire direction to current scan }
  137.             WHILE (scan(srdegree, res) > 0) AND (old_dam = damage) DO
  138.               BEGIN
  139.                 Range := scan(srdegree, res); { shoot while you can }
  140.                 IF (Range > 40) AND (Range < 800) THEN { good shooting range }
  141.                   BEGIN 
  142.                     hitem;
  143.                     srdegree := course;
  144.                   END; 
  145.                 chkloc; { change direction if necessary }
  146.                 drive(degree, 100);
  147.               END; 
  148.             srdegree := srdegree-20; { next degree to scan }
  149.           END; 
  150.         degree := degree-90; { try again }
  151.       END; 
  152.   END; { end of Marvin Main }
  153.  
  154.   
  155.